/*	=======================================================================	*/
/// <remarks>
/// Version:
///		- number:	1.0.4
///		- build:	20060605
///		- status:	dev
/// </remarks>
/*	=======================================================================	*/
/// <remarks>
/// Class: X_Common
/// The X_Common object class has the following purpose/function:
///	- this is a javascript class for all dialogs
/// </remarks>
/*	-----------------------------------------------------------------------	*/
/// <summary>
/// The X_Common object class is constructed as follows:
///		var thisobj = new X_Common(dbg);
/// - where:
///		- dbg:	debugging switch
/// </summary>
function X_Common(dbg) {
	/*	-------------------------------------------	*/
	/// <remarks>Properties: Public</remarks>
	/*	-------------------------------------------	*/
	this.parameter = "";
	/*	-------------------------------------------	*/
	/// <remarks>Properties: Private</remarks>
	/*	-------------------------------------------	*/
	var _self = this;	// self allows for a method/property to be called internally
	var _debug = (dbg)? dbg : false;
	var _id = "X_Common";
	/*	-------------------------------------------	*/
	/// <remarks>Region: Accessor methods</remarks>
	/*	-------------------------------------------	*/
	this.GetID = function() { return(_id); }
	/*	-------------------------------------------	*/
	/// <remarks>Region: Public methods</remarks>
	/*	-------------------------------------------	*/
	this.GetE = _GetE;
	this.ShowE = _ShowE;
	this.SetAttribute = _SetAttribute;
	this.GetAttribute = _GetAttribute;
	this.IsDigit = _IsDigit;
	this.OpenFileBrowser = _OpenFileBrowser;
	/// <summary>Method:_GetE - Gets a element by its Id. Used for shorter coding.</summary>
	function _GetE( elementId ) {
		return document.getElementById( elementId )  ;
	}
	/// <summary>Method:_ShowE</summary>
	function _ShowE( element, isVisible ) {
		if ( typeof( element ) == 'string' )
			element = GetE( element ) ;
		element.style.display = isVisible ? '' : 'none' ;
	}
	/// <summary>Method:_SetAttribute</summary>
	function _SetAttribute( element, attName, attValue ) {
		if ( attValue == null || attValue.length == 0 )
			element.removeAttribute( attName, 0 ) ;			// 0 : Case Insensitive
		else
			element.setAttribute( attName, attValue, 0 ) ;	// 0 : Case Insensitive
	}
	/// <summary>Method:_Template</summary>
	function _GetAttribute( element, attName, valueIfNull ) {
		var oAtt = element.attributes[attName] ;
		if ( oAtt == null || !oAtt.specified )
			return valueIfNull ? valueIfNull : '' ;
		var oValue ;
		if ( !( oValue = element.getAttribute( attName, 2 ) ) )
			oValue = oAtt.nodeValue ;
		return ( oValue == null ? valueIfNull : oValue ) ;
	}
	/// <summary>Method:_IsDigit - function used by text fields to accept numbers only.</summary>
	function _IsDigit( e ) {
		e = e || event ;
		var iCode = ( e.keyCode || e.charCode ) ;
		event.returnValue =
			(
				( iCode >= 48 && iCode <= 57 )		// Numbers
				|| (iCode >= 37 && iCode <= 40)		// Arrows
				|| iCode == 8						// Backspace
				|| iCode == 46						// Delete
			) ;
		return event.returnValue ;
	}
	/// <summary>Method:_OpenFileBrowser</summary>
	// Possibly not required for x_dialog's
	function _OpenFileBrowser( url, width, height ) {
		// oEditor must be defined.
		var iLeft = ( oEditor.FCKConfig.ScreenWidth  - width ) / 2 ;
		var iTop  = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;
	
		var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
		sOptions += ",width=" + width ;
		sOptions += ",height=" + height ;
		sOptions += ",left=" + iLeft ;
		sOptions += ",top=" + iTop ;
	
		// The "PreserveSessionOnFileBrowser" because the above code could be 
		// blocked by popup blockers.
		if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE ) {
			// The following change has been made otherwise IE will open the file 
			// browser on a different server session (on some cases):
			// http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
			// by Simone Chiaretta.
			var oWindow = oEditor.window.open( url, 'FCKBrowseWindow', sOptions ) ;
			if ( oWindow )
				oWindow.opener = window ;
			else
				alert( oEditor.FCKLang.BrowseServerBlocked ) ;
	    }
	    else
			window.open( url, 'FCKBrowseWindow', sOptions ) ;
	}
}
/*	=======================================================================	*/
/// <remarks>
/// Extension of the String object
/// </remarks>
/*	-----------------------------------------------------------------------	*/
/// <summary>Method:trim</summary>
String.prototype.trim = function() {
	return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
}
/// <summary>Method:startsWith</summary>
String.prototype.startsWith = function( value ) {
	return ( this.substr( 0, value.length ) == value ) ;
}
/// <summary>Method:remove</summary>
String.prototype.remove = function( start, length ) {
	var s = '' ;
	if ( start > 0 )
		s = this.substring( 0, start ) ;
	if ( start + length < this.length )
		s += this.substring( start + length , this.length ) ;
	return s ;
}
